<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>管理系统</title>
    <link rel="stylesheet" href="../static/layui/css/layui.css" />
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css">
  </head>
  <body>
    <div class="layui-layout layui-layout-admin">
      <div class="layui-header">
        <div class="layui-logo">
          <i class="fa fa-cloud" style="font-size: 25px;"></i>&nbsp; 管理系统
        </div>
        <!-- 头部区域（可配合layui 已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
          <li class="layui-nav-item"><a th:action="@{/userLogin}"><i class="fa fa-home"></i> 首页</a></li>
          <li class="layui-nav-item"><a href=""><i class="fa fa-compass"></i> 位置</a></li>
          <li class="layui-nav-item"><a href=""><i class="fa fa-pie-chart"></i> 历史</a></li>
          <li class="layui-nav-item"><a href="javascript:;"><i class="fa fa-phone"></i> 联系我们</a>
            <dl class="layui-nav-child">
              <dd>
                <a href="https://bueryouth.github.io/"><i class="fa fa-star"></i> 在线客服</a>
              </dd>
              <dd>
                <a href="https://bueryouth.github.io/"><i class="fa fa-star"></i> 联系电话</a>
              </dd>
              <dd>
                <a href="https://bueryouth.github.io/"><i class="fa fa-star"></i> 官方网站</a>
              </dd>
            </dl>
          </li>
        </ul>
        <ul class="layui-nav layui-layout-right">
          <li class="layui-nav-item"><a href="javascript:;"> 欢迎&nbsp;<span th:text="${username}"></span>&nbsp;登录！&nbsp;
              <i class="fa fa-user-o" style="font-size: 25px;"></i>
            </a>
            <dl class="layui-nav-child">
              <dd>
                <a href="">个人详情</a>
              </dd>
              <dd>
                <a href="">信息修改</a>
              </dd>
            </dl>
          </li>
          <li class="layui-nav-item"><a th:href="@{'/exit?token='}+${token}">退出</a></li>
        </ul>
      </div>

      <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
          <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
          <ul class="layui-nav layui-nav-tree" lay-filter="test">
            <li class="layui-nav-item"><a href="javascript:;">用户管理</a>
              <dl class="layui-nav-child">
                <dd>
                  <a class="site-demo-active" data-type="tabAdd1" th:href="@{'/account?token='}+${token}"
                    target="ifm">全部用户</a>
                </dd>
                <dd>
                  <a class="site-demo-active" data-type="tabAdd1"
                    th:attr="data-url='/main/account?token='+${token}">个人信息</a>
                </dd>
              </dl>
            </li>
            <li class="layui-nav-item"><a href="javascript:;">资源管理</a>
              <dl class="layui-nav-child">
                <dd>
                  <a class="site-demo-active" data-type="tabAdd1" th:href="@{'/upload?token='}+${token}"
                    target="ifm">文件上传</a>
                </dd>
                <dd>
                  <a class="site-demo-active" data-type="tabAdd1" th:href="@{'/download?token='}+${token}"
                    target="ifm">文件下载</a>
                </dd>
                <dd>
                  <a class="site-demo-active" data-type="tabAdd1" href="https://static.runoob.com/images/demo/demo3.jpg"
                    target="ifm">新建壁纸</a>
                </dd>
              </dl>
            </li>

            <li class="layui-nav-item"><a class="" href="javascript:;">系统管理</a>
              <dl class="layui-nav-child">
                <dd>
                  <a href="javascript:;" class="site-demo-active" data-type="tabAdd">新增页面</a>
                </dd>
                <dd>
                  <a href="javascript:;" class="site-demo-active" data-type="tabDelete">删除页面</a>
                </dd>
                <dd>
                  <a href="javascript:;" class="site-demo-active" data-type="tabChange">切换页面</a>
                </dd>
              </dl>
            </li>
            <li class="layui-nav-item"><a th:href="@{'/exit?token='}+${token}">退出系统</a></li>
          </ul>
        </div>
      </div>

      <div class="layui-body">
        <!-- 内容主体区域 -->
        <div class="layui-tab" lay-filter="demo" lay-allowclose="true">
          <ul class="layui-tab-title">
            <li class="layui-this" lay-id="1">默认首页</li>
          </ul>
          <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
              <iframe th:src="@{/main}" name="ifm" width="1330px" height="550px"></iframe>
            </div>
          </div>
        </div>
      </div>

      <div class="layui-footer">
        <!-- 底部固定区域 -->
        @不二青年·2020-2021
      </div>
    </div>

    <script src="../static/layui/layui.js"></script>
    <script>
      var lent = 1;
      layui.use('element', function() {
        var $ = layui.jquery;
        element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
        //触发事件
        var active = {
          tabAdd: function() {
            //新增一个Tab项
            element.tabAdd('demo', {
              title: '新选项' + ++lent,
              content: '内容' + lent,
              id: lent
              //实际使用一般是规定好的id，这里以时间戳模拟下
            });
            element.tabChange('demo', lent);
          },
          tabAdd1: function(e) {
            //新增一个Tab项
            console.log(e.context.href);
            element.tabAdd('demo', {
              title: e.text(),
              content: '<iframe src="' + e.context.href +
                '" width="1330px" height="550px"></iframe>',
              // content: '<div class="layui-tab-item layui-show"><iframe name="ifm" width="1330px" height="550px"></iframe></div>',
              id: ++lent
            });
            element.tabChange('demo', lent);
          },
          tabDelete: function(othis) {
            //删除指定Tab项
            element.tabDelete('demo', lent--); //删除：“商品管理”
            othis.addClass('layui-btn-disabled');
          },
          tabChange: function(e) {
            //切换到指定Tab项
            element.tabChange('demo', 3); //切换到：用户管理
          }
        };
        $('.site-demo-active').on('click', function() {
          var othis = $(this),
            type = othis.data('type');
          active[type] ? active[type].call(this, othis) : '';
        });
        //Hash地址的定位
        var layid = location.hash.replace(/^#test=/, '');
        element.tabChange('test', layid);

        element.on('tab(test)', function(elem) {
          location.hash = 'test=' + $(this).attr('lay-id');
        });
      });
    </script>
  </body>
</html>
